package app;

import com.wu.annotation.WebServlet;
import com.wu.http.server.MyWriter;
import com.wu.javax.servlet.http.Cookie;
import com.wu.javax.servlet.http.HttpServlet;
import com.wu.javax.servlet.http.HttpServletRequest;
import com.wu.javax.servlet.http.HttpServletResponse;

/**
 * @program: tomcatServer
 * @author: 吴磊
 * @create: 2021-12-30 18:33
 */
@WebServlet("/login")
public class LoginController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        //System.out.println(request.getSession().getId());
        //System.out.println(request.getSession());
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String content = username + ":" + password;
        Cookie[] cookies = response.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie);
        }
        //String content = request.getJsonParams();
        //PrintWriter out = response.getWriter();
        //String protocal200 = "HTTP/1.0 200 OK\r\nContent-Type: application/json;charset=utf-8\r\nContent-Length: "
        //        + content.getBytes().length + "\r\n";
        //out.println(protocal200);
        //out.println(content);
        //out.flush();
        MyWriter out = response.getMyWriter();
        out.println(content);

    }
}
